package com.yvon.maple.service.msg.core.handler.pending;

import cn.hutool.core.collection.CollUtil;
import com.yvon.maple.service.msg.core.handler.handler.HandlerHolder;
import com.yvon.maple.service.msg.core.common.domain.TaskInfo;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author : Yvon
 * @since : 2021-12-23
 */
@Data
@Accessors(chain = true)
@Slf4j
public class Task implements Runnable{

    @Autowired
    private HandlerHolder handlerHolder;

    private TaskInfo taskInfo;

    @Override
    public void run() {

        if (CollUtil.isNotEmpty(taskInfo.getReceiver())) {
            handlerHolder.getHandler(taskInfo.getChannelType().getCode())
                    .doHandler(taskInfo);
        }

    }
}
